@namespace AntDesign.Pro.Layout
@inherits AntProComponentBase

<Menu
    Mode="Mode"
    DefaultOpenKeys="OpenKeys"
    Theme="NavTheme"
    Style="@Style"
    Class="@ClassMapper.Class"
    OnOpenChange="SetOpenKeys"
    InlineCollapsed="Collapsed">
    @menuItemTemplate((MenuData, false))
</Menu>

@code
{
    static readonly RenderFragment<MenuDataItem> title= menuItem => @<span>
                                                                        @if (!string.IsNullOrEmpty(menuItem.Icon))
                                                                        {
                                                                            <Icon Type="@menuItem.Icon" Theme="outline"/>
                                                                        }
                                                                        <span>@menuItem.Name</span>
                                                                    </span>;

    static readonly RenderFragment<(MenuDataItem[] items, bool isChildren)> menuItemTemplate = context =>
        @<Template>
            @if (context.items != null)
            {
                @foreach (var menuItem in context.items)
                {
                    if (menuItem.Children != null && !menuItem.HideChildrenInMenu)
                    {
                        <SubMenu TitleTemplate="@title(menuItem)" Key="@menuItem.Key">
                            @menuItemTemplate((menuItem.Children, true))       
                        </SubMenu>
                    }
                    else
                    {
                        <MenuItem Key="@menuItem.Key">
                            <MenuLink href="@menuItem.Path">
                                @title(menuItem)
                            </MenuLink>
                        </MenuItem>
                    }
                }
            }
        </Template>;
}
